<?php
namespace Controller;

use Hoa\Registry\Registry;
use Library\Log;
use Library\View;
use Logic\ProdLogic;
use Model\Prod;
use Service\OrderService;


/**
 * OrderController
 * @author los_gsy
 */
class OrderController extends BaseController {
	/**
	 * 构造函数
	 */
	public function __construct() {
		parent::__construct();
	}


	/**
	 * test
	 */
	public function test() {
		echo __METHOD__, '<br />';
	}


	/**
	 * 下单
	 */
	public function placeOrder() {
		//获取参数
		$prodId = I('get.prodId', 1);

		//查询产品信息
		$prod = Prod::getProd($prodId);
		$prodCnt = ProdLogic::getProdCnt($prodId);

		//Success
		$data = [];
		$data['prod'] = $prod;
		$data['prodCnt'] = $prodCnt;
		View::display('Order/placeOrder', $data);
	}


	/**
	 * do下单
	 */
	public function doPlaceOrder() {
		//获取参数
		$prodId = I('post.prodId');
		$prodQty = I('post.prodQty');

		//下单
		$result = OrderService::placeOrder($prodId, $prodQty);

		//Success
		echo json_encode($result);
	}


	/**
	 * do下单，成功
	 */
	public function doPlaceOrderSuccess() {
		//Success
		View::display('Order/doPlaceOrderSuccess');
	}


}